package com.emperor.service.impl;

import com.emperor.entity.VmType;
import com.emperor.mapper.VmTypeMapper;
import com.emperor.service.VmTypeService;
import com.emperor.vo.SkuClassPageVo;
import com.emperor.vo.SkuVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VmTypeServiceImpl implements VmTypeService {
    @Autowired
    private VmTypeMapper vmTypeMapper;

    @Override
    public SkuClassPageVo findAll(Integer pageIndex, Integer pageSize, String className) {
        PageHelper.startPage(pageIndex, pageSize);
        Page<VmType> page = (Page<VmType>) vmTypeMapper.findAll(className);
        System.out.println(page.getResult());
        long l = (page.getTotal() / pageSize) + 1;
        SkuClassPageVo build = SkuClassPageVo.builder().
                pageIndex(pageIndex).
                pageSize(pageSize)
                .totalPage((int) l).totalCount((int) page.getTotal())
                .currentPageRecords(page.getResult()).build();
        return build;
    }

    @Override
    public void addVmType(VmType vmType) {
        vmTypeMapper.addVmType(vmType);
    }

    @Override
    public void updateVmType(Integer typeId, VmType vmType) {
        vmTypeMapper.updateVmType(typeId, vmType);
    }

    @Override
    public void deleteVmType(Integer typeId) {
        vmTypeMapper.deleteVmType(typeId);
    }
}
